﻿
using Dapper;
using SIG.DAL.Dapper.Model;
using System;
using System.Collections.Generic;
using System.Data.Common;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SIG.DAL.Dapper.Repositories
{
    public class PageMetaRepository
    {
        private DbConnection _connection;
        public PageMeta GetPageMeta(ModelType moduleType, string objectId)
        {
            IEnumerable<PageMeta> result;
            using (_connection = Utilities.GetOpenConnection())
            {
                result = _connection.GetList<PageMeta>(new { ModelType = (short)moduleType , ObjectId = objectId });
            }
            return result.FirstOrDefault();
        }

        public int? Create(PageMeta model)
        {
            int? result;
            using (_connection = Utilities.GetOpenConnection())
            {
                result = _connection.Insert(model);
            }
            return result;
        }

        public int Update(PageMeta model)
        {
            int result;
            using (_connection = Utilities.GetOpenConnection())
            {
                result = _connection.Update(model);
            }
            return result;
        }
        public int Delete(PageMeta model)
        {
            int result;
            using (_connection = Utilities.GetOpenConnection())
            {
                result = _connection.Delete(model);
            }
            return result;
        }

        public int Delete(int id)
        {
            int result;
            using (_connection = Utilities.GetOpenConnection())
            {
                result = _connection.Delete<PageMeta>(id);
            }
            return result;
        }
    }
}
